ddi <- read_ipums_ddi("atus_00005.xml")
csv <- read_ipums_micro(ddi) %>%
  clean_names()
## Use of data from IPUMS ATUS is subject to conditions including that users
## should cite the data appropriately. Use command `ipums_conditions()` for more
## details.
data
## function (..., list = character(), package = NULL, lib.loc = NULL, 
##     verbose = getOption("verbose"), envir = .GlobalEnv, overwrite = TRUE) 
## {
##     fileExt <- function(x) {
##         db <- grepl("\\.[^.]+\\.(gz|bz2|xz)$", x)
##         ans <- sub(".*\\.", "", x)
##         ans[db] <- sub(".*\\.([^.]+\\.)(gz|bz2|xz)$", "\\1\\2", 
##             x[db])
##         ans
##     }
##     my_read_table <- function(...) {
##         lcc <- Sys.getlocale("LC_COLLATE")
##         on.exit(Sys.setlocale("LC_COLLATE", lcc))
##         Sys.setlocale("LC_COLLATE", "C")
##         read.table(...)
##     }
##     stopifnot(is.character(list))
##     names <- c(as.character(substitute(list(...))[-1L]), list)
##     if (!is.null(package)) {
##         if (!is.character(package)) 
##             stop("'package' must be a character vector or NULL")
##     }
##     paths <- find.package(package, lib.loc, verbose = verbose)
##     if (is.null(lib.loc)) 
##         paths <- c(path.package(package, TRUE), if (!length(package)) getwd(), 
##             paths)
##     paths <- unique(normalizePath(paths[file.exists(paths)]))
##     paths <- paths[dir.exists(file.path(paths, "data"))]
##     dataExts <- tools:::.make_file_exts("data")
##     if (length(names) == 0L) {
##         db <- matrix(character(), nrow = 0L, ncol = 4L)
##         for (path in paths) {
##             entries <- NULL
##             packageName <- if (file_test("-f", file.path(path, 
##                 "DESCRIPTION"))) 
##                 basename(path)
##             else "."
##             if (file_test("-f", INDEX <- file.path(path, "Meta", 
##                 "data.rds"))) {
##                 entries <- readRDS(INDEX)
##             }
##             else {
##                 dataDir <- file.path(path, "data")
##                 entries <- tools::list_files_with_type(dataDir, 
##                   "data")
##                 if (length(entries)) {
##                   entries <- unique(tools::file_path_sans_ext(basename(entries)))
##                   entries <- cbind(entries, "")
##                 }
##             }
##             if (NROW(entries)) {
##                 if (is.matrix(entries) && ncol(entries) == 2L) 
##                   db <- rbind(db, cbind(packageName, dirname(path), 
##                     entries))
##                 else warning(gettextf("data index for package %s is invalid and will be ignored", 
##                   sQuote(packageName)), domain = NA, call. = FALSE)
##             }
##         }
##         colnames(db) <- c("Package", "LibPath", "Item", "Title")
##         footer <- if (missing(package)) 
##             paste0("Use ", sQuote(paste("data(package =", ".packages(all.available = TRUE))")), 
##                 "\n", "to list the data sets in all *available* packages.")
##         else NULL
##         y <- list(title = "Data sets", header = NULL, results = db, 
##             footer = footer)
##         class(y) <- "packageIQR"
##         return(y)
##     }
##     paths <- file.path(paths, "data")
##     for (name in names) {
##         found <- FALSE
##         for (p in paths) {
##             tmp_env <- if (overwrite) 
##                 envir
##             else new.env()
##             if (file_test("-f", file.path(p, "Rdata.rds"))) {
##                 rds <- readRDS(file.path(p, "Rdata.rds"))
##                 if (name %in% names(rds)) {
##                   found <- TRUE
##                   if (verbose) 
##                     message(sprintf("name=%s:\t found in Rdata.rds", 
##                       name), domain = NA)
##                   thispkg <- sub(".*/([^/]*)/data$", "\\1", p)
##                   thispkg <- sub("_.*$", "", thispkg)
##                   thispkg <- paste0("package:", thispkg)
##                   objs <- rds[[name]]
##                   lazyLoad(file.path(p, "Rdata"), envir = tmp_env, 
##                     filter = function(x) x %in% objs)
##                   break
##                 }
##                 else if (verbose) 
##                   message(sprintf("name=%s:\t NOT found in names() of Rdata.rds, i.e.,\n\t%s\n", 
##                     name, paste(names(rds), collapse = ",")), 
##                     domain = NA)
##             }
##             if (file_test("-f", file.path(p, "Rdata.zip"))) {
##                 warning("zipped data found for package ", sQuote(basename(dirname(p))), 
##                   ".\nThat is defunct, so please re-install the package.", 
##                   domain = NA)
##                 if (file_test("-f", fp <- file.path(p, "filelist"))) 
##                   files <- file.path(p, scan(fp, what = "", quiet = TRUE))
##                 else {
##                   warning(gettextf("file 'filelist' is missing for directory %s", 
##                     sQuote(p)), domain = NA)
##                   next
##                 }
##             }
##             else {
##                 files <- list.files(p, full.names = TRUE)
##             }
##             files <- files[grep(name, files, fixed = TRUE)]
##             if (length(files) > 1L) {
##                 o <- match(fileExt(files), dataExts, nomatch = 100L)
##                 paths0 <- dirname(files)
##                 paths0 <- factor(paths0, levels = unique(paths0))
##                 files <- files[order(paths0, o)]
##             }
##             if (length(files)) {
##                 for (file in files) {
##                   if (verbose) 
##                     message("name=", name, ":\t file= ...", .Platform$file.sep, 
##                       basename(file), "::\t", appendLF = FALSE, 
##                       domain = NA)
##                   ext <- fileExt(file)
##                   if (basename(file) != paste0(name, ".", ext)) 
##                     found <- FALSE
##                   else {
##                     found <- TRUE
##                     zfile <- file
##                     zipname <- file.path(dirname(file), "Rdata.zip")
##                     if (file.exists(zipname)) {
##                       Rdatadir <- tempfile("Rdata")
##                       dir.create(Rdatadir, showWarnings = FALSE)
##                       topic <- basename(file)
##                       rc <- .External(C_unzip, zipname, topic, 
##                         Rdatadir, FALSE, TRUE, FALSE, FALSE)
##                       if (rc == 0L) 
##                         zfile <- file.path(Rdatadir, topic)
##                     }
##                     if (zfile != file) 
##                       on.exit(unlink(zfile))
##                     switch(ext, R = , r = {
##                       library("utils")
##                       sys.source(zfile, chdir = TRUE, envir = tmp_env)
##                     }, RData = , rdata = , rda = load(zfile, 
##                       envir = tmp_env), TXT = , txt = , tab = , 
##                       tab.gz = , tab.bz2 = , tab.xz = , txt.gz = , 
##                       txt.bz2 = , txt.xz = assign(name, my_read_table(zfile, 
##                         header = TRUE, as.is = FALSE), envir = tmp_env), 
##                       CSV = , csv = , csv.gz = , csv.bz2 = , 
##                       csv.xz = assign(name, my_read_table(zfile, 
##                         header = TRUE, sep = ";", as.is = FALSE), 
##                         envir = tmp_env), found <- FALSE)
##                   }
##                   if (found) 
##                     break
##                 }
##                 if (verbose) 
##                   message(if (!found) 
##                     "*NOT* ", "found", domain = NA)
##             }
##             if (found) 
##                 break
##         }
##         if (!found) {
##             warning(gettextf("data set %s not found", sQuote(name)), 
##                 domain = NA)
##         }
##         else if (!overwrite) {
##             for (o in ls(envir = tmp_env, all.names = TRUE)) {
##                 if (exists(o, envir = envir, inherits = FALSE)) 
##                   warning(gettextf("an object named %s already exists and will not be overwritten", 
##                     sQuote(o)))
##                 else assign(o, get(o, envir = tmp_env, inherits = FALSE), 
##                   envir = envir)
##             }
##             rm(tmp_env)
##         }
##     }
##     invisible(names)
## }
## <bytecode: 0x156bbd238>
## <environment: namespace:utils>
#csv <- read_csv(file = "atus_00001.csv.gz") %>%
 # clean_names()

# race 
race_file <- read_excel("race_980x.xlsx")

race_file <- race_file %>%
  rename(code1 = race) %>%
  rename(race = code) 

csv <- left_join(csv, race_file, by = "race") %>%
  rename(race_code = race) %>%
  rename(race = code1)


# education
education_file <- read_excel("Education.xlsx")
education_file <- education_file %>%
  rename(code_educ = educ) %>%
  rename(educ = code_education) %>%
  mutate(educ = as.numeric(educ))

csv <- left_join(csv, education_file, by = "educ") %>%
  rename(code_education = educ) %>%
  rename(educ = code_educ) 

# marital status
marital_file <- read_excel("marital_status.xlsx")
education_file <- marital_file %>%
  mutate(marst = as.numeric(marst))
  
csv <- left_join(csv, marital_file, by = "marst") %>%
  rename(code_marst = marst) %>%
  rename(marst = marst_code) %>%
  mutate(marst_simple = ifelse(code_marst <= 2, "Married", ifelse(code_marst >= 6, "Never Married", "Separated/Divorced")))



# age
csv <- csv %>%
  filter(age > 18)

# children
csv <- csv %>%
  mutate(child = ifelse(yngch < 19, 1, 0) )

# gender

csv <- csv %>%
  mutate(gender = ifelse(sex == 1, "male", "female")) 

# years 

csv %>%
  summary(earnweek)
##       year          caseid              pernum      lineno       wt06          
##  Min.   :2003   Min.   :2.003e+13   Min.   :1   Min.   :1   Min.   :   419472  
##  1st Qu.:2006   1st Qu.:2.006e+13   1st Qu.:1   1st Qu.:1   1st Qu.:  2932235  
##  Median :2011   Median :2.011e+13   Median :1   Median :1   Median :  5230098  
##  Mean   :2011   Mean   :2.011e+13   Mean   :1   Mean   :1   Mean   :  7201674  
##  3rd Qu.:2016   3rd Qu.:2.016e+13   3rd Qu.:1   3rd Qu.:1   3rd Qu.:  8816158  
##  Max.   :2021   Max.   :2.021e+13   Max.   :1   Max.   :1   Max.   :209010030  
##                                                             NA's   :8469       
##       wt20                age             sex          race_code  
##  Min.   :        0   Min.   :19.00   Min.   :1.000   Min.   :100  
##  1st Qu.:  3606315   1st Qu.:36.00   1st Qu.:1.000   1st Qu.:100  
##  Median :  6475784   Median :48.00   Median :2.000   Median :100  
##  Mean   :  8746744   Mean   :49.48   Mean   :1.563   Mean   :104  
##  3rd Qu.: 11222184   3rd Qu.:62.00   3rd Qu.:2.000   3rd Qu.:100  
##  Max.   :137151708   Max.   :85.00   Max.   :2.000   Max.   :599  
##  NA's   :199330                                                   
##    code_marst    code_education    educyrs       empstat_cps8     fullpart    
##  Min.   :1.000   Min.   :10.0   Min.   :101.0   Min.   :1.00   Min.   : 1.00  
##  1st Qu.:1.000   1st Qu.:21.0   1st Qu.:112.0   1st Qu.:1.00   1st Qu.: 1.00  
##  Median :1.000   Median :30.0   Median :214.0   Median :1.00   Median : 1.00  
##  Mean   :2.764   Mean   :29.7   Mean   :190.4   Mean   :2.72   Mean   :37.06  
##  3rd Qu.:4.000   3rd Qu.:40.0   3rd Qu.:216.0   3rd Qu.:5.00   3rd Qu.:99.00  
##  Max.   :6.000   Max.   :43.0   Max.   :321.0   Max.   :7.00   Max.   :99.00  
##                                                                               
##     earnweek            eldch          yngch           nchild      
##  Min.   :     0.0   Min.   : 0.0   Min.   : 0.00   Min.   :0.0000  
##  1st Qu.:   673.1   1st Qu.:13.0   1st Qu.: 9.00   1st Qu.:0.0000  
##  Median :  1846.2   Median :99.0   Median :99.00   Median :0.0000  
##  Mean   : 44392.0   Mean   :60.8   Mean   :59.44   Mean   :0.8366  
##  3rd Qu.:100000.0   3rd Qu.:99.0   3rd Qu.:99.00   3rd Qu.:2.0000  
##  Max.   :100000.0   Max.   :99.0   Max.   :99.00   Max.   :9.0000  
##                                                                    
##    bls_carehh         bls_comm          bls_educ           bls_food      
##  Min.   :   0.00   Min.   :   0.00   Min.   :   0.000   Min.   :   0.00  
##  1st Qu.:   0.00   1st Qu.:   0.00   1st Qu.:   0.000   1st Qu.:  30.00  
##  Median :   0.00   Median :   0.00   Median :   0.000   Median :  60.00  
##  Mean   :  38.93   Mean   :  10.74   Mean   :   8.373   Mean   :  75.24  
##  3rd Qu.:  30.00   3rd Qu.:   0.00   3rd Qu.:   0.000   3rd Qu.: 100.00  
##  Max.   :1230.00   Max.   :1200.00   Max.   :1190.000   Max.   :1320.00  
##                                                                          
##    bls_hhact         bls_leis      bls_leis_arts      bls_leis_attend  
##  Min.   :   0.0   Min.   :   0.0   Min.   :   0.000   Min.   :  0.000  
##  1st Qu.:  15.0   1st Qu.: 155.0   1st Qu.:   0.000   1st Qu.:  0.000  
##  Median :  75.0   Median : 294.0   Median :   0.000   Median :  0.000  
##  Mean   : 124.9   Mean   : 329.4   Mean   :   5.879   Mean   :  6.128  
##  3rd Qu.: 185.0   3rd Qu.: 475.0   3rd Qu.:   0.000   3rd Qu.:  0.000  
##  Max.   :1405.0   Max.   :1439.0   Max.   :1015.000   Max.   :860.000  
##                                                                        
##  bls_leis_attsport  bls_leis_partsport bls_leis_relax    bls_leis_soc   
##  Min.   :   0.000   Min.   :   0.00    Min.   :   0.0   Min.   :   0.0  
##  1st Qu.:   0.000   1st Qu.:   0.00    1st Qu.:  90.0   1st Qu.: 130.0  
##  Median :   0.000   Median :   0.00    Median : 195.0   Median : 255.0  
##  Mean   :   1.832   Mean   :  16.25    Mean   : 245.3   Mean   : 297.7  
##  3rd Qu.:   0.000   3rd Qu.:   0.00    3rd Qu.: 356.0   3rd Qu.: 425.0  
##  Max.   :1030.000   Max.   :1125.00    Max.   :1439.0   Max.   :1439.0  
##                                                                         
##  bls_leis_soccom   bls_leis_soccomex bls_leis_sport    bls_leis_travel  
##  Min.   :   0.00   Min.   :   0.00   Min.   :   0.00   Min.   :   0.00  
##  1st Qu.:   0.00   1st Qu.:   0.00   1st Qu.:   0.00   1st Qu.:   0.00  
##  Median :   0.00   Median :   0.00   Median :   0.00   Median :   0.00  
##  Mean   :  46.38   Mean   :  40.22   Mean   :  18.15   Mean   :  13.54  
##  3rd Qu.:  60.00   3rd Qu.:  45.00   3rd Qu.:   0.00   3rd Qu.:  12.00  
##  Max.   :1350.00   Max.   :1350.00   Max.   :1125.00   Max.   :1350.00  
##                                                                         
##   bls_leis_tv       bls_pcare      bls_purch         bls_social     
##  Min.   :   0.0   Min.   :   0   Min.   :   0.00   Min.   :   0.00  
##  1st Qu.:  40.0   1st Qu.: 490   1st Qu.:   0.00   1st Qu.:   0.00  
##  Median : 122.0   Median : 564   Median :   0.00   Median :   0.00  
##  Mean   : 176.9   Mean   : 574   Mean   :  49.23   Mean   :  25.12  
##  3rd Qu.: 255.0   3rd Qu.: 645   3rd Qu.:  73.00   3rd Qu.:   0.00  
##  Max.   :1433.0   Max.   :1440   Max.   :1320.00   Max.   :1325.00  
##                                                                     
##     bls_work          race               educ              marst          
##  Min.   :   0.0   Length:216908      Length:216908      Length:216908     
##  1st Qu.:   0.0   Class :character   Class :character   Class :character  
##  Median :   0.0   Mode  :character   Mode  :character   Mode  :character  
##  Mean   : 176.7                                                           
##  3rd Qu.: 438.2                                                           
##  Max.   :1430.0                                                           
##                                                                           
##  marst_simple           child          gender         
##  Length:216908      Min.   :0.000   Length:216908     
##  Class :character   1st Qu.:0.000   Class :character  
##  Mode  :character   Median :0.000   Mode  :character  
##                     Mean   :0.385                     
##                     3rd Qu.:1.000                     
##                     Max.   :1.000                     
## 
# employed
csv <- csv %>%
  mutate(empstat_cps8 = as.numeric(empstat_cps8)) %>%
  mutate(emp = ifelse(empstat_cps8<= 2, "Employed", ifelse(empstat_cps8>=5, "Not In Labour Force", "Unemployed")))

# race
csv %>%
  count(race, sort = TRUE) %>%
  filter(n > 1000)
#We can see that top 5 groups > 1000 people

csv <- csv %>%
  filter(race %in% c("White only", "Black only", "Asian only", "American Indian, Alaskan Native", "White-American Indian")) 

view(c)
#leisure hours aggregate
csv %>%
  ggplot(mapping = aes(x = bls_leis)) +
  geom_histogram(binwidth=50) +
  labs(
  title = "Distribution of daily individual leisure minutes",
  x = "Daily Minutes",
  y = "Count",
  caption = "Data from ATUS",
) 

csv %>%
  filter(year %in% c(2007, 2009)) %>%
  ggplot(mapping = aes(x = bls_leis)) +
  geom_histogram(binwidth=50) +
  facet_wrap(~year) +
  labs(
  title = "Distribution of daily individual leisure minutes",
  x = "Daily Minutes",
  y = "Count",
  caption = "Data from ATUS",
)

#leisure hours aggregate by gender
csv %>%
  filter(year < 2020) %>%
  group_by(gender) %>%
  ggplot(mapping = aes(x = bls_leis) )+
  geom_histogram(binwidth=50) +
  facet_wrap(~ gender) +
    labs(
  title = "Distribution of daily individual leisure minutes",
  x = "Daily Minutes",
  y = "Count",
  caption = "Data from ATUS",
)

csv %>%
  filter(year %in% c(2007, 2009)) %>%
  ggplot(mapping = aes(x = bls_leis)) +
  geom_histogram(binwidth=50) +
  facet_wrap(~ gender + year) +
  labs(
  title = "Distribution of daily individual leisure minutes",
  x = "Daily Minutes",
  y = "Count",
  caption = "Data from ATUS",
)

# Median
csv %>%
  filter(year < 2020) %>%
  group_by(gender, year) %>%
  summarize(median_leisure = weighted.median(bls_leis, as.numeric(wt06), na.rm=TRUE)) %>%
  clean_names() %>%
  ggplot(aes(x = year, y = median_leisure)) +
  geom_line() +
  facet_wrap(~ gender) +
  labs(
  title = "Median daily individual leisure minutes by gender",
  y = "Daily Minutes",
  x = "Year",
  caption = "Data from ATUS",
) 
## `summarise()` has grouped output by 'gender'. You can override using the
## `.groups` argument.

# mean
csv %>%
  filter(year < 2020) %>%
  group_by(gender,year) %>%
  summarize(new = weighted.mean(bls_leis, wt06)) %>%
  clean_names() %>%
  ggplot(aes(x = year, y = new)) +
  geom_line() +
  facet_wrap(~ gender) +
  labs(
  title = "Weighted mean daily individual leisure minutes by gender",
  y = "Daily Minutes",
  x = "Year",
  caption = "Data from ATUS",
) 
## `summarise()` has grouped output by 'gender'. You can override using the
## `.groups` argument.

# Median 
csv %>%
  filter(year > 2005) %>%
  filter(year < 2011) %>%
  group_by(year, gender) %>%
  summarize(median_bls_leis = weighted.median(bls_leis, wt06)) %>%
  clean_names() %>%
  ggplot(aes(x = year, y = median_bls_leis)) +
  geom_line() +
  facet_wrap(~ gender) +
  labs(
  title = "Weighted median daily individual leisure minutes by gender",
  y = "Daily Minutes",
  x = "Year",
  caption = "Data from ATUS",
) 
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.

# Mean
csv %>%
  filter(year > 2005) %>%
  filter(year < 2011) %>%
  group_by(year, gender) %>%
  summarize(mean_bls_leis = weighted.mean(bls_leis, wt06)) %>%
  clean_names() %>%
  ggplot(aes(x = year, y = mean_bls_leis)) +
  geom_line() +
  facet_wrap(~ gender) +
  labs(
  title = "Mean daily individual leisure minutes by gender",
  y = "Daily Minutes",
  x = "Year",
  caption = "Data from ATUS",
) 
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.

# All Quantile
csv %>%
  filter(year < 2020) %>%
  group_by(year, gender) %>%
  summarize(quantile_25 = weighted.quantile(bls_leis, wt06, prob = 0.25), quantile_50 = weighted.quantile(bls_leis, wt06, prob = 0.50), quantile_75 = weighted.quantile(bls_leis, wt06, prob = 0.75)) %>%
  clean_names() %>%
  pivot_longer(quantile_25:quantile_75, names_to = "quantile", values_to = "hours") %>%
  ggplot(aes(x = year, y = hours, group = quantile, colour = quantile)) +
  geom_line() +
    facet_wrap(~ gender) +
  labs(
  title = "Weighted daily individual leisure minutes by gender",
  y = "Daily Minutes",
  x = "Year",
  caption = "Data from ATUS",
) 
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.

# by year, gender
csv %>%
  filter(year < 2020) %>%
  group_by(year, gender) %>%
  summarize(quantile_25 = weighted.quantile(bls_leis, wt06, prob = 0.25), quantile_50 = weighted.quantile(bls_leis, wt06, prob = 0.50), quantile_75 = weighted.quantile(bls_leis, wt06, prob = 0.75)) %>%
  clean_names() %>%
  pivot_longer(quantile_25:quantile_75, names_to = "quantile", values_to = "hours") %>%
  filter(year > 2005) %>%
  filter(year < 2011) %>%
  ggplot(aes(x = year, y = hours, group = quantile, colour = quantile)) +
  geom_line() +
  facet_wrap(~gender) +
    labs(
  title = "Weighted daily individual leisure minutes by gender",
  y = "Daily Minutes",
  x = "Year",
  caption = "Data from ATUS",
) 
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.

# by year, gender
csv %>%
  group_by(year, gender) %>%
  summarize(median = median(bls_leis)) %>%
  clean_names() %>%
  filter(year > 2005) %>%
  filter(year < 2011) %>%
  ggplot(aes(x = year, y = median)) +
  geom_line() +
  facet_wrap(~gender) +
      labs(
  title = "Daily individual leisure minutes by gender",
  y = "Daily Minutes",
  x = "Year",
  caption = "Data from ATUS",
) 
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.

#csv %>%
 # ggplot(mapping = aes(x = year, y = bls_leis)) + 
 # geom_jitter(alpha = 0.01)
#naive regression of men versus women
  

g <- csv %>%
  lm(formula = bls_leis ~ gender, weight = wt06)
summary(g)
## 
## Call:
## lm(formula = bls_leis ~ gender, data = ., weights = wt06)
## 
## Weighted Residuals:
##      Min       1Q   Median       3Q      Max 
## -3873300  -353387   -33870   343917  6366061 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 291.1692     0.6646  438.10   <2e-16 ***
## gendermale   39.5660     0.9574   41.33   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 583600 on 206819 degrees of freedom
##   (8382 observations deleted due to missingness)
## Multiple R-squared:  0.008191,   Adjusted R-squared:  0.008186 
## F-statistic:  1708 on 1 and 206819 DF,  p-value: < 2.2e-16
#naive regression of men versus women + year 

y <- csv %>%
  lm(formula = bls_leis ~ gender + year, weight = wt06)

# race count
newcsv <- csv %>%
 filter(race_code <= 210)

newcsv
newcsv %>%
  lm(formula = bls_leis ~ gender + year + age + race, weight = wt06) 
## 
## Call:
## lm(formula = bls_leis ~ gender + year + age + race, data = ., 
##     weights = wt06)
## 
## Coefficients:
##               (Intercept)                 gendermale  
##                  16.98725                   44.88100  
##                      year                        age  
##                   0.07276                    3.15759  
##            raceAsian only             raceBlack only  
##                 -65.93934                   15.86296  
##            raceWhite only  raceWhite-American Indian  
##                 -28.02202                  -10.83630
# 
a <- newcsv %>%
  lm(formula = bls_leis ~ gender + year + age + race, weight = wt06) 
summary(a)
## 
## Call:
## lm(formula = bls_leis ~ gender + year + age + race, data = ., 
##     weights = wt06)
## 
## Weighted Residuals:
##      Min       1Q   Median       3Q      Max 
## -3099397  -342415   -41506   308384  7238310 
## 
## Coefficients:
##                            Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                16.98725  176.24323   0.096  0.92321    
## gendermale                 44.88100    0.92435  48.554  < 2e-16 ***
## year                        0.07276    0.08759   0.831  0.40618    
## age                         3.15759    0.02661 118.658  < 2e-16 ***
## raceAsian only            -65.93934    5.79279 -11.383  < 2e-16 ***
## raceBlack only             15.86296    5.47901   2.895  0.00379 ** 
## raceWhite only            -28.02202    5.34053  -5.247 1.55e-07 ***
## raceWhite-American Indian -10.83630    7.81604  -1.386  0.16562    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 562700 on 206813 degrees of freedom
##   (8382 observations deleted due to missingness)
## Multiple R-squared:  0.07786,    Adjusted R-squared:  0.07783 
## F-statistic:  2494 on 7 and 206813 DF,  p-value: < 2.2e-16
newcsv
# education
newcsv1 <- newcsv %>%
  mutate(new_educ = ifelse(code_education <= 17, "<High School", ifelse(code_education >= 40, ">Four Year Degree", "High School Graduate")))

  
b <- newcsv1 %>%
  lm(formula = bls_leis ~ gender + year + age + race + new_educ, weight = wt06) 
summary(b)
## 
## Call:
## lm(formula = bls_leis ~ gender + year + age + race + new_educ, 
##     data = ., weights = wt06)
## 
## Weighted Residuals:
##      Min       1Q   Median       3Q      Max 
## -3205427  -332218   -33792   311237  7647075 
## 
## Coefficients:
##                                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                  -767.53425  175.41369  -4.376 1.21e-05 ***
## gendermale                     44.48196    0.91728  48.493  < 2e-16 ***
## year                            0.47850    0.08721   5.487 4.10e-08 ***
## age                             3.10516    0.02645 117.377  < 2e-16 ***
## raceAsian only                -39.06627    5.76687  -6.774 1.25e-11 ***
## raceBlack only                 21.64222    5.43741   3.980 6.89e-05 ***
## raceWhite only                -16.10388    5.30318  -3.037  0.00239 ** 
## raceWhite-American Indian      -5.47262    7.75613  -0.706  0.48045    
## new_educ>Four Year Degree     -77.85439    1.61267 -48.277  < 2e-16 ***
## new_educHigh School Graduate  -28.36747    1.50248 -18.880  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 558300 on 206811 degrees of freedom
##   (8382 observations deleted due to missingness)
## Multiple R-squared:  0.09221,    Adjusted R-squared:  0.09217 
## F-statistic:  2334 on 9 and 206811 DF,  p-value: < 2.2e-16
# with children
 

c <- newcsv1 %>%
  lm(formula = bls_leis ~ gender + year + age + race + new_educ + nchild, weight = wt06) 
summary(c)
## 
## Call:
## lm(formula = bls_leis ~ gender + year + age + race + new_educ + 
##     nchild, data = ., weights = wt06)
## 
## Weighted Residuals:
##      Min       1Q   Median       3Q      Max 
## -3411543  -317557   -22904   312665  7269668 
## 
## Coefficients:
##                                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                  -459.06351  173.17810  -2.651  0.00803 ** 
## gendermale                     41.22445    0.90640  45.482  < 2e-16 ***
## year                            0.35450    0.08609   4.118 3.83e-05 ***
## age                             2.68428    0.02672 100.460  < 2e-16 ***
## raceAsian only                -44.53755    5.69220  -7.824 5.13e-15 ***
## raceBlack only                 15.60231    5.36718   2.907  0.00365 ** 
## raceWhite only                -22.53617    5.23480  -4.305 1.67e-05 ***
## raceWhite-American Indian     -15.36305    7.65623  -2.007  0.04479 *  
## new_educ>Four Year Degree     -84.51939    1.59420 -53.017  < 2e-16 ***
## new_educHigh School Graduate  -37.72979    1.48827 -25.352  < 2e-16 ***
## nchild                        -30.89065    0.41662 -74.145  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 551100 on 206810 degrees of freedom
##   (8382 observations deleted due to missingness)
## Multiple R-squared:  0.1157, Adjusted R-squared:  0.1157 
## F-statistic:  2706 on 10 and 206810 DF,  p-value: < 2.2e-16
#marital status

d <- newcsv1 %>%
  lm(formula = bls_leis ~ gender + year + age + race + new_educ + nchild + marst_simple, weight = wt06) 
summary(d)
## 
## Call:
## lm(formula = bls_leis ~ gender + year + age + race + new_educ + 
##     nchild + marst_simple, data = ., weights = wt06)
## 
## Weighted Residuals:
##      Min       1Q   Median       3Q      Max 
## -3573012  -318323   -24660   309070  7016453 
## 
## Coefficients:
##                                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                    -13.59818  172.67882  -0.079 0.937233    
## gendermale                      42.06056    0.90823  46.310  < 2e-16 ***
## year                             0.10110    0.08589   1.177 0.239151    
## age                              3.33576    0.03273 101.929  < 2e-16 ***
## raceAsian only                 -38.52564    5.66762  -6.797 1.07e-11 ***
## raceBlack only                  10.40823    5.34310   1.948 0.051419 .  
## raceWhite only                 -17.97103    5.21122  -3.449 0.000564 ***
## raceWhite-American Indian      -11.93607    7.62035  -1.566 0.117270    
## new_educ>Four Year Degree      -77.05326    1.59799 -48.219  < 2e-16 ***
## new_educHigh School Graduate   -34.25177    1.48356 -23.088  < 2e-16 ***
## nchild                         -22.37572    0.45781 -48.876  < 2e-16 ***
## marst_simpleNever Married       58.01406    1.34945  42.991  < 2e-16 ***
## marst_simpleSeparated/Divorced  24.53589    1.26743  19.359  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 548500 on 206808 degrees of freedom
##   (8382 observations deleted due to missingness)
## Multiple R-squared:  0.1241, Adjusted R-squared:  0.124 
## F-statistic:  2441 on 12 and 206808 DF,  p-value: < 2.2e-16
stargazer(a, b, c, d, title="Various Models", align=TRUE, type = "html")
Various Models
Dependent variable:
bls_leis
(1) (2) (3) (4)
gendermale 44.881*** 44.482*** 41.224*** 42.061***
(0.924) (0.917) (0.906) (0.908)
year 0.073 0.479*** 0.354*** 0.101
(0.088) (0.087) (0.086) (0.086)
age 3.158*** 3.105*** 2.684*** 3.336***
(0.027) (0.026) (0.027) (0.033)
raceAsian only -65.939*** -39.066*** -44.538*** -38.526***
(5.793) (5.767) (5.692) (5.668)
raceBlack only 15.863*** 21.642*** 15.602*** 10.408*
(5.479) (5.437) (5.367) (5.343)
raceWhite only -28.022*** -16.104*** -22.536*** -17.971***
(5.341) (5.303) (5.235) (5.211)
raceWhite-American Indian -10.836 -5.473 -15.363** -11.936
(7.816) (7.756) (7.656) (7.620)
new_educ> Four Year Degree -77.854*** -84.519*** -77.053***
(1.613) (1.594) (1.598)
new_educHigh School Graduate -28.367*** -37.730*** -34.252***
(1.502) (1.488) (1.484)
nchild -30.891*** -22.376***
(0.417) (0.458)
marst_simpleNever Married 58.014***
(1.349)
marst_simpleSeparated/Divorced 24.536***
(1.267)
Constant 16.987 -767.534*** -459.064*** -13.598
(176.243) (175.414) (173.178) (172.679)
Observations 206,821 206,821 206,821 206,821
R2 0.078 0.092 0.116 0.124
Adjusted R2 0.078 0.092 0.116 0.124
Residual Std. Error 562,740.400 (df = 206813) 558,347.100 (df = 206811) 551,072.100 (df = 206810) 548,461.500 (df = 206808)
F Statistic 2,494.496*** (df = 7; 206813) 2,334.080*** (df = 9; 206811) 2,706.253*** (df = 10; 206810) 2,441.352*** (df = 12; 206808)
Note: p<0.1; p<0.05; p<0.01
newcsv1 %>%
  filter(year > 2006) %>%
  filter(year < 2011) %>%
  group_by(year) %>%
  count(emp) %>%
  filter(emp == "Unemployed") %>%
  ggplot(mapping = aes(x = year, y = n)) +
  geom_line() +
  labs(
  title = "Unemployment",
  y = "Daily Minutes",
  x = "Count",
  caption = "Data from ATUS",
)

  #facet_wrap(~emp)

newcsv1 %>%
  ggplot(mapping = aes(x = bls_leis)) +
  geom_histogram() +
  facet_wrap(~emp) +
  labs(
  title = "Daily individual leisure minutes by employment type",
  y = "Count",
  x = "Daily Minutes",
  caption = "Data from ATUS",
)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

newcsv1 %>%
  filter(year < 2020) %>%
  group_by(emp, gender, new_educ, year) %>%
  summarize(median = weighted.median(bls_leis, wt06)) %>%
  ggplot(mapping = aes(x = year, y = median, group = new_educ, colour = new_educ)) +
  geom_line() +
  facet_wrap(~gender + emp) +
  labs(
  title = "Weighted daily individual leisure minutes",
  y = "Daily Minutes",
  x = "Count",
  caption = "Data from ATUS",
)
## `summarise()` has grouped output by 'emp', 'gender', 'new_educ'. You can
## override using the `.groups` argument.

newcsv1 %>%
  filter(year < 2020) %>%
  group_by(emp, gender, new_educ, year) %>%
  summarize(median = median(bls_leis)) %>%
  ggplot(mapping = aes(x = year, y = median, group = new_educ, colour = new_educ)) +
  geom_line() +
  facet_wrap(~gender + emp) +
  labs(
  title = "Daily individual leisure minutes",
  y = "Daily Minutes",
  x = "Count",
  caption = "Data from ATUS",
)
## `summarise()` has grouped output by 'emp', 'gender', 'new_educ'. You can
## override using the `.groups` argument.

newcsv1 %>%
  filter(year > 2006) %>%
  filter(year < 2011) %>%
  group_by(emp, gender, new_educ, year) %>%
  summarize(median = weighted.median(bls_leis, wt06)) %>%
  ggplot(mapping = aes(x = year, y = median, group = new_educ, colour = new_educ)) +
  geom_line() +
  facet_wrap(~gender + emp) +
  labs(
  title = "Weighted daily individual leisure minutes",
  y = "Daily Minutes",
  x = "Count",
  caption = "Data from ATUS",
)
## `summarise()` has grouped output by 'emp', 'gender', 'new_educ'. You can
## override using the `.groups` argument.

newcsv1 %>%
  filter(year > 2006) %>%
  filter(year < 2011) %>%
  group_by(emp, gender, new_educ, year) %>%
  summarize(median = median(bls_leis)) %>%
  ggplot(mapping = aes(x = year, y = median, group = new_educ, colour = new_educ)) +
  geom_line() +
  facet_wrap(~gender + emp) +
  labs(
  title = "Daily individual leisure minutes",
  y = "Daily Minutes",
  x = "Count",
  caption = "Data from ATUS",
)
## `summarise()` has grouped output by 'emp', 'gender', 'new_educ'. You can
## override using the `.groups` argument.

count_table <- newcsv1 %>%
  filter(year > 2006) %>%
  filter(year < 2011) %>%
  group_by(emp, gender) %>%
  tally()

count_table2 <- newcsv1 %>%
  filter(year > 2006) %>%
  filter(year < 2011) %>%
  group_by(emp, gender, new_educ) %>%
  tally()
  
kable(count_table2) %>% kable_styling()
emp gender new_educ n
Employed female <High School 897
Employed female >Four Year Degree 6163
Employed female High School Graduate 8703
Employed male <High School 1260
Employed male >Four Year Degree 5823
Employed male High School Graduate 7913
Not In Labour Force female <High School 2104
Not In Labour Force female >Four Year Degree 2236
Not In Labour Force female High School Graduate 6251
Not In Labour Force male <High School 996
Not In Labour Force male >Four Year Degree 1059
Not In Labour Force male High School Graduate 2800
Unemployed female <High School 130
Unemployed female >Four Year Degree 216
Unemployed female High School Graduate 613
Unemployed male <High School 144
Unemployed male >Four Year Degree 168
Unemployed male High School Graduate 581
kable(count_table) %>% kable_styling()
emp gender n
Employed female 15763
Employed male 14996
Not In Labour Force female 10591
Not In Labour Force male 4855
Unemployed female 959
Unemployed male 893
newcsv1 %>%
  filter(year > 2006) %>%
  filter(year < 2011) %>%
  group_by(emp, year) %>%
  tally() %>%
  pivot_wider(names_from = year, values_from = n) %>%
  clean_names() %>%
  mutate(change_2008 = x2008-x2007) %>%
  mutate(change_2009 = x2009-x2008) %>%
  mutate(change_2010 = x2010-x2009) %>%
  select(1, 6:8) %>%
  kbl() %>%
  kable_styling()
emp change_2008 change_2009 change_2010
Employed 305 -3 -70
Not In Labour Force 111 241 7
Unemployed 57 250 129
#Change

change <- newcsv1 %>%
  filter(year<2020) %>%
  group_by(gender,  year, new_educ, child, marst_simple) %>%
  summarize(median_bls_leis = weighted.median(bls_leis, wt06)) %>%
  clean_names() %>%
  pivot_wider(values_from = median_bls_leis, names_from = year) %>%
  clean_names() %>%
  mutate(leisure_change = x2009 - x2007)
## `summarise()` has grouped output by 'gender', 'year', 'new_educ', 'child'. You
## can override using the `.groups` argument.
change11 <- newcsv1 %>%
  filter(year<2020) %>%
  group_by(gender,  year, new_educ, child, marst_simple, emp) %>%
   summarize(median_bls_leis = weighted.median(bls_leis, wt06)) %>%
  clean_names() %>%
  pivot_wider(values_from = median_bls_leis, names_from = year) %>%
  clean_names() %>%
  mutate(leisure_change = x2009 - x2007)
## `summarise()` has grouped output by 'gender', 'year', 'new_educ', 'child',
## 'marst_simple'. You can override using the `.groups` argument.
change2 <- newcsv1 %>%
  filter(year<2020) %>%
  group_by(gender, year) %>%
  summarize(median_bls_leis = weighted.median(bls_leis, wt06)) %>%
  clean_names() %>%
  pivot_wider(values_from = median_bls_leis, names_from = year) %>%
  clean_names() %>%
  mutate(leisure_change = x2009 - x2007)
## `summarise()` has grouped output by 'gender'. You can override using the
## `.groups` argument.
change3 <- newcsv1 %>%
  filter(year<2020) %>%
  group_by(gender,  year, new_educ, nchild, marst_simple) %>%
   summarize(median_bls_leis = weighted.median(bls_leis, wt06)) %>%
  clean_names() %>%
  pivot_wider(values_from = median_bls_leis, names_from = year) %>%
  clean_names() %>%
  mutate(leisure_change = x2009 - x2007)
## `summarise()` has grouped output by 'gender', 'year', 'new_educ', 'nchild'. You
## can override using the `.groups` argument.
change4 <- newcsv1 %>%
  filter(year<2020) %>%
  group_by(gender,  year, new_educ, nchild, marst_simple) %>%
  summarize(mean(bls_leis)) %>%
  clean_names() %>%
  pivot_wider(values_from = mean_bls_leis, names_from = year) %>%
  clean_names() %>%
  mutate(leisure_change = x2009 - x2007)
## `summarise()` has grouped output by 'gender', 'year', 'new_educ', 'nchild'. You
## can override using the `.groups` argument.
change12 <- newcsv1 %>%
  filter(year<2020) %>%
  group_by(gender,  year, emp) %>%
   summarize(median_bls_leis = weighted.median(bls_leis, wt06)) %>%
  clean_names() %>%
  pivot_wider(values_from = median_bls_leis, names_from = year) %>%
  clean_names() %>%
  mutate(leisure_change = x2009 - x2007)
## `summarise()` has grouped output by 'gender', 'year'. You can override using
## the `.groups` argument.
#child
newcsv1
delta <- change %>%
  lm(formula = leisure_change ~ gender+ new_educ+ child+ marst_simple)
summary(delta)
## 
## Call:
## lm(formula = leisure_change ~ gender + new_educ + child + marst_simple, 
##     data = .)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -102.31  -45.97   -4.24   20.53  327.07 
## 
## Coefficients:
##                                Estimate Std. Error t value Pr(>|t|)  
## (Intercept)                       15.75      35.42   0.445   0.6598  
## gendermale                        26.56      26.77   0.992   0.3295  
## new_educ>Four Year Degree        -54.63      32.79  -1.666   0.1065  
## new_educHigh School Graduate     -59.46      32.79  -1.813   0.0802 .
## child                             25.33      26.77   0.946   0.3519  
## marst_simpleNever Married         29.62      32.79   0.903   0.3737  
## marst_simpleSeparated/Divorced    55.29      32.79   1.686   0.1025  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 80.32 on 29 degrees of freedom
## Multiple R-squared:  0.2325, Adjusted R-squared:  0.07367 
## F-statistic: 1.464 on 6 and 29 DF,  p-value: 0.2253
delta11 <- change11 %>%
  lm(formula = leisure_change ~ gender+ new_educ+ child+ marst_simple + emp)
summary(delta11)
## 
## Call:
## lm(formula = leisure_change ~ gender + new_educ + child + marst_simple + 
##     emp, data = .)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -425.50  -44.46   -2.07   51.23  564.03 
## 
## Coefficients:
##                                Estimate Std. Error t value Pr(>|t|)
## (Intercept)                     -16.928     38.221  -0.443    0.659
## gendermale                       38.210     25.429   1.503    0.136
## new_educ>Four Year Degree       -28.840     31.364  -0.920    0.360
## new_educHigh School Graduate     -8.585     30.726  -0.279    0.781
## child                            29.654     25.429   1.166    0.246
## marst_simpleNever Married        -0.576     30.726  -0.019    0.985
## marst_simpleSeparated/Divorced   26.363     30.999   0.850    0.397
## empNot In Labour Force           20.970     30.467   0.688    0.493
## empUnemployed                    31.192     31.303   0.996    0.322
## 
## Residual standard error: 128.3 on 94 degrees of freedom
##   (5 observations deleted due to missingness)
## Multiple R-squared:  0.06103,    Adjusted R-squared:  -0.01888 
## F-statistic: 0.7637 on 8 and 94 DF,  p-value: 0.6354
delta12 <- change12 %>%
  lm(formula = leisure_change ~ gender + emp)
summary(delta12)
## 
## Call:
## lm(formula = leisure_change ~ gender + emp, data = .)
## 
## Residuals:
##       1       2       3       4       5       6 
## -4.5833  3.9167  0.6667  4.5833 -3.9167 -0.6667 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)
## (Intercept)               9.583      4.953   1.935    0.193
## gendermale              -14.167      4.953  -2.860    0.104
## empNot In Labour Force    3.000      6.066   0.495    0.670
## empUnemployed             3.750      6.066   0.618    0.599
## 
## Residual standard error: 6.066 on 2 degrees of freedom
## Multiple R-squared:  0.8115, Adjusted R-squared:  0.5288 
## F-statistic:  2.87 on 3 and 2 DF,  p-value: 0.269
delta4 <- change4 %>%
  lm(formula = leisure_change ~ gender+ new_educ+ nchild+ marst_simple)
summary(delta4)
## 
## Call:
## lm(formula = leisure_change ~ gender + new_educ + nchild + marst_simple, 
##     data = .)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -485.10  -36.83   -1.40   37.40  411.07 
## 
## Coefficients:
##                                Estimate Std. Error t value Pr(>|t|)  
## (Intercept)                      12.665     30.131   0.420   0.6752  
## gendermale                       17.502     21.562   0.812   0.4191  
## new_educ>Four Year Degree        -9.619     27.471  -0.350   0.7270  
## new_educHigh School Graduate    -57.623     26.066  -2.211   0.0296 *
## nchild                            5.253      6.039   0.870   0.3867  
## marst_simpleNever Married        18.920     26.865   0.704   0.4831  
## marst_simpleSeparated/Divorced   20.875     26.184   0.797   0.4274  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 106 on 90 degrees of freedom
##   (56 observations deleted due to missingness)
## Multiple R-squared:  0.07284,    Adjusted R-squared:  0.01103 
## F-statistic: 1.178 on 6 and 90 DF,  p-value: 0.325
delta3 <- change4 %>%
  lm(formula = leisure_change ~ gender+ new_educ+ nchild+ marst_simple)
summary(delta3)
## 
## Call:
## lm(formula = leisure_change ~ gender + new_educ + nchild + marst_simple, 
##     data = .)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -485.10  -36.83   -1.40   37.40  411.07 
## 
## Coefficients:
##                                Estimate Std. Error t value Pr(>|t|)  
## (Intercept)                      12.665     30.131   0.420   0.6752  
## gendermale                       17.502     21.562   0.812   0.4191  
## new_educ>Four Year Degree        -9.619     27.471  -0.350   0.7270  
## new_educHigh School Graduate    -57.623     26.066  -2.211   0.0296 *
## nchild                            5.253      6.039   0.870   0.3867  
## marst_simpleNever Married        18.920     26.865   0.704   0.4831  
## marst_simpleSeparated/Divorced   20.875     26.184   0.797   0.4274  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 106 on 90 degrees of freedom
##   (56 observations deleted due to missingness)
## Multiple R-squared:  0.07284,    Adjusted R-squared:  0.01103 
## F-statistic: 1.178 on 6 and 90 DF,  p-value: 0.325
delta <- change %>%
  lm(formula = leisure_change ~ gender+ new_educ+ child+ marst_simple)
summary(delta)
## 
## Call:
## lm(formula = leisure_change ~ gender + new_educ + child + marst_simple, 
##     data = .)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -102.31  -45.97   -4.24   20.53  327.07 
## 
## Coefficients:
##                                Estimate Std. Error t value Pr(>|t|)  
## (Intercept)                       15.75      35.42   0.445   0.6598  
## gendermale                        26.56      26.77   0.992   0.3295  
## new_educ>Four Year Degree        -54.63      32.79  -1.666   0.1065  
## new_educHigh School Graduate     -59.46      32.79  -1.813   0.0802 .
## child                             25.33      26.77   0.946   0.3519  
## marst_simpleNever Married         29.62      32.79   0.903   0.3737  
## marst_simpleSeparated/Divorced    55.29      32.79   1.686   0.1025  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 80.32 on 29 degrees of freedom
## Multiple R-squared:  0.2325, Adjusted R-squared:  0.07367 
## F-statistic: 1.464 on 6 and 29 DF,  p-value: 0.2253
delta3 <- change3 %>%
  lm(formula = leisure_change ~ gender+ new_educ+ nchild+ marst_simple)
summary(delta3)
## 
## Call:
## lm(formula = leisure_change ~ gender + new_educ + nchild + marst_simple, 
##     data = .)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -498.92  -50.39   -5.51   42.70  317.13 
## 
## Coefficients:
##                                Estimate Std. Error t value Pr(>|t|)   
## (Intercept)                      48.757     31.561   1.545  0.12589   
## gendermale                       12.490     22.586   0.553  0.58164   
## new_educ>Four Year Degree       -38.077     28.775  -1.323  0.18911   
## new_educHigh School Graduate    -83.422     27.303  -3.055  0.00296 **
## nchild                           -2.675      6.325  -0.423  0.67338   
## marst_simpleNever Married        33.372     28.140   1.186  0.23878   
## marst_simpleSeparated/Divorced   11.390     27.426   0.415  0.67890   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 111.1 on 90 degrees of freedom
##   (56 observations deleted due to missingness)
## Multiple R-squared:  0.1187, Adjusted R-squared:   0.06 
## F-statistic: 2.021 on 6 and 90 DF,  p-value: 0.07087
stargazer(delta, delta3, title="Models for Change in Leisure", align=TRUE, type = "html")
Models for Change in Leisure
Dependent variable:
leisure_change
(1) (2)
gendermale 26.556 12.490
(26.774) (22.586)
new_educ> Four Year Degree -54.625 -38.077
(32.791) (28.775)
new_educHigh School Graduate -59.458* -83.422***
(32.791) (27.303)
child 25.333
(26.774)
nchild -2.675
(6.325)
marst_simpleNever Married 29.625 33.372
(32.791) (28.140)
marst_simpleSeparated/Divorced 55.292 11.390
(32.791) (27.426)
Constant 15.750 48.757
(35.418) (31.561)
Observations 36 97
R2 0.232 0.119
Adjusted R2 0.074 0.060
Residual Std. Error 80.321 (df = 29) 111.064 (df = 90)
F Statistic 1.464 (df = 6; 29) 2.021* (df = 6; 90)
Note: p<0.1; p<0.05; p<0.01
# First Set

time_model <- newcsv1 %>%
  filter(year < 2020) %>%
  mutate(year = as.character(year)) %>%
  lm(formula = bls_leis ~ gender + year + gender*year + age + race + new_educ,weights = wt06 ) 


# W employment
time_model1 <- newcsv1 %>%
  filter(year < 2020) %>%
  mutate(year = as.character(year)) %>%
  lm(formula = bls_leis ~ gender + year + gender*year + age + race + new_educ + emp, weights = wt06) 


# W emp*gender

time_model2 <- newcsv1 %>%
  filter(year < 2020) %>%
  mutate(year = as.character(year)) %>%
  lm(formula = bls_leis ~ gender + year + gender*year + age + race + new_educ + emp + emp*year, weights = wt06) 
stargazer(time_model, time_model1, time_model2, title="Models for Change in Leisure", align=TRUE, type = "html")
Models for Change in Leisure
Dependent variable:
bls_leis
(1) (2) (3)
gendermale 39.829*** 58.683*** 56.412***
(4.027) (3.876) (3.937)
year2004 2.681 1.926 -1.407
(3.935) (3.785) (4.499)
year2005 -0.739 0.015 -1.114
(3.925) (3.774) (4.476)
year2006 -4.414 -4.360 -6.608
(3.918) (3.768) (4.477)
year2007 -2.882 -0.944 -6.943
(3.911) (3.761) (4.447)
year2008 3.106 4.451 -3.258
(3.899) (3.750) (4.444)
year2009 7.625* 6.642* 4.859
(3.891) (3.742) (4.451)
year2010 -0.655 -0.828 -5.133
(3.887) (3.738) (4.439)
year2011 5.361 3.698 -0.861
(3.875) (3.727) (4.438)
year2012 9.270** 6.612* 1.999
(3.855) (3.707) (4.427)
year2013 9.821** 7.287** -0.636
(3.849) (3.701) (4.415)
year2014 9.443** 6.297* -5.211
(3.838) (3.691) (4.409)
year2015 3.608 1.368 -1.531
(3.830) (3.684) (4.387)
year2016 -1.301 -4.232 -6.159
(3.821) (3.674) (4.388)
year2017 11.251*** 8.194** -3.354
(3.813) (3.667) (4.382)
year2018 3.638 3.225 -3.053
(3.803) (3.657) (4.332)
year2019 5.749 6.586* -0.647
(3.805) (3.660) (4.330)
age 3.094*** 1.709*** 1.709***
(0.027) (0.029) (0.029)
raceAsian only -37.695*** -36.472*** -36.648***
(5.873) (5.648) (5.647)
raceBlack only 24.153*** 26.537*** 26.499***
(5.522) (5.310) (5.310)
raceWhite only -14.910*** -5.620 -5.796
(5.383) (5.178) (5.177)
raceWhite-American Indian -4.329 -1.609 -1.628
(7.857) (7.556) (7.556)
new_educ> Four Year Degree -79.114*** -40.393*** -40.544***
(1.638) (1.604) (1.604)
new_educHigh School Graduate -29.473*** -8.872*** -9.037***
(1.521) (1.472) (1.473)
empNot In Labour Force 136.188*** 122.813***
(1.093) (4.319)
empUnemployed 95.913*** 98.418***
(2.487) (10.932)
gendermale:year2004 6.486 4.541 6.086
(5.674) (5.457) (5.535)
gendermale:year2005 3.416 1.430 2.338
(5.661) (5.444) (5.523)
gendermale:year2006 8.166 7.070 8.769
(5.645) (5.429) (5.511)
gendermale:year2007 6.286 5.090 7.715
(5.628) (5.413) (5.492)
gendermale:year2008 2.926 1.641 4.928
(5.616) (5.400) (5.484)
gendermale:year2009 1.905 -1.026 -0.024
(5.603) (5.388) (5.466)
gendermale:year2010 10.019* 4.883 6.773
(5.595) (5.381) (5.456)
gendermale:year2011 0.772 -2.884 -1.599
(5.581) (5.367) (5.441)
gendermale:year2012 11.527** 8.987* 11.115**
(5.555) (5.342) (5.418)
gendermale:year2013 1.888 -1.915 0.820
(5.544) (5.332) (5.404)
gendermale:year2014 6.157 4.827 8.595
(5.534) (5.322) (5.399)
gendermale:year2015 3.626 0.517 2.544
(5.517) (5.306) (5.375)
gendermale:year2016 7.718 8.137 9.565*
(5.508) (5.296) (5.376)
gendermale:year2017 -4.234 -4.298 0.283
(5.496) (5.285) (5.363)
gendermale:year2018 13.606** 7.703 10.325*
(5.476) (5.267) (5.329)
gendermale:year2019 1.795 -2.721 0.020
(5.477) (5.268) (5.335)
year2004:empNot In Labour Force 8.477
(6.006)
year2005:empNot In Labour Force 3.656
(6.017)
year2006:empNot In Labour Force 8.783
(5.979)
year2007:empNot In Labour Force 15.855***
(5.979)
year2008:empNot In Labour Force 20.036***
(5.974)
year2009:empNot In Labour Force 4.625
(5.954)
year2010:empNot In Labour Force 10.931*
(5.955)
year2011:empNot In Labour Force 8.703
(5.915)
year2012:empNot In Labour Force 12.243**
(5.867)
year2013:empNot In Labour Force 18.586***
(5.842)
year2014:empNot In Labour Force 26.201***
(5.827)
year2015:empNot In Labour Force 10.730*
(5.783)
year2016:empNot In Labour Force 7.608
(5.788)
year2017:empNot In Labour Force 30.558***
(5.781)
year2018:empNot In Labour Force 16.597***
(5.726)
year2019:empNot In Labour Force 17.916***
(5.758)
year2004:empUnemployed 0.779
(15.381)
year2005:empUnemployed -12.601
(15.241)
year2006:empUnemployed -44.486***
(16.016)
year2007:empUnemployed -5.890
(17.242)
year2008:empUnemployed -1.336
(15.701)
year2009:empUnemployed -2.220
(13.948)
year2010:empUnemployed -0.594
(13.538)
year2011:empUnemployed 23.668*
(13.760)
year2012:empUnemployed -4.078
(13.983)
year2013:empUnemployed 15.636
(14.099)
year2014:empUnemployed 31.286**
(14.458)
year2015:empUnemployed -43.427***
(15.375)
year2016:empUnemployed -37.259**
(16.119)
year2017:empUnemployed -19.841
(15.413)
year2018:empUnemployed -9.487
(16.974)
year2019:empUnemployed 15.429
(16.728)
Constant 191.251*** 169.998*** 175.466***
(6.251) (6.019) (6.251)
Observations 198,136 198,136 198,136
R2 0.093 0.161 0.161
Adjusted R2 0.092 0.161 0.161
Residual Std. Error 552,444.400 (df = 198095) 531,266.400 (df = 198093) 531,134.900 (df = 198061)
F Statistic 505.293*** (df = 40; 198095) 903.938*** (df = 42; 198093) 515.058*** (df = 74; 198061)
Note: p<0.1; p<0.05; p<0.01
#stargazer(time_modela, time_model1a, time_model2a8, title="Models for Change in Leisure", align=TRUE, type = "html")